<template>
  <div class="pictureInfo-container">
    <div class="hd">
      <h2>{{pictureInfo.title}}</h2>
      <p>
        <span>发布时间：{{pictureInfo.add_time | dateFormat('YYYY/MM/DD HH:mm:ss')}}</span>
        <span>阅读量：{{pictureInfo.click}}</span>
      </p>
    </div>
    <van-divider :style="{ borderColor: '#1989fa'}" />
    <div class="bd">
      <img v-for="(item, index) in pictureInfo.imgs"
           :key="index"
           :src="item"
           @click="imgPreview(index)">
    </div>
    <div class="content">{{pictureInfo.content}}</div>
    <comment :id="id" />
  </div>
</template>

<script>
import comment from '@/components/Comment.vue'
import { ImagePreview } from 'vant'

export default {
  data() {
    return {
      id: this.$route.params.id,
      pictureInfo: {}
    }
  },
  created() {
    this.getPictureInfo()
  },
  methods: {
    // 获取图片详情
    getPictureInfo() {
      this.axios.get('/picture/getPictureInfo', { params: { _id: this.id } }).then(res => {
        if (res.data.code == 1) {
          this.pictureInfo = res.data.pictureInfo
        }
      })
    },
    // 图片预览
    imgPreview(index) {
      ImagePreview({
        images: this.pictureInfo.imgs,
        startPosition: index
      })
    }
  },
  components: { comment }
}
</script>

<style lang="scss">
.pictureInfo-container {
  .hd {
    padding: 0 0.2rem;
    h2 {
      margin: 0.1rem 0 0.2rem 0;
    }
    p {
      margin: 0;
      display: flex;
      justify-content: space-between;
    }
  }
  .bd {
    display: flex;
    flex-wrap: wrap;
    padding: 0 0.2rem;
    img {
      width: 28vw;
      height: 22vw;
      margin: 0 0.2rem 0.4rem;
    }
  }
  .content {
    padding: 0 0.3rem 0.3rem 0.3rem;
    font-size: 0.35rem;
    line-height: 0.6rem;
  }
}
</style>